package com.kapcb.secure.configuration.core;

import com.kapcb.secure.configuration.enums.AlgorithmType;
import com.kapcb.secure.configuration.enums.EncodeType;
import com.kapcb.secure.configuration.filter.SecureUtils;

/**
 * <a>Title: AesEncryptor </a>
 * <a>Author: kapcb <a>
 * <a>Description: AesEncryptor <a>
 *
 * @author Kpacb
 * @version 1.0
 * @date 2024/5/5 9:47
 * @since 1.0
 */
public class AesEncryptor extends AbstractSecurerProvider {

    private final EncryptContext encryptContext;

    public AesEncryptor(EncryptContext encryptContext) {
        super(encryptContext);
        this.encryptContext = encryptContext;
    }

    /**
     * 获得当前算法
     */
    @Override
    public AlgorithmType algorithm() {
        return AlgorithmType.AES;
    }

    @Override
    public String encrypt(String value, EncodeType encodeType) {
        if (encodeType == EncodeType.HEX) {
            return SecureUtils.encryptByAesHex(value, encryptContext.getSecret());
        } else {
            return SecureUtils.encryptByAes(value, encryptContext.getSecret());
        }
    }

    @Override
    public String decrypt(String value) {
        return SecureUtils.decryptByAes(value, encryptContext.getSecret());
    }
}
